package com.tedu.springboot2206.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import qrcode.QRCodeUtil;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;

@Controller
public class QRController {
    @RequestMapping("/createQR")
    public void qr(HttpServletRequest request, HttpServletResponse response) {
        {
            String line = request.getParameter("content");
            System.out.println("二维码内容:" + line);
            OutputStream out = null;
            try {
                out = response.getOutputStream();
            } catch (IOException e) {
                e.printStackTrace();
            }

            try {
                response.setContentType("image/jpeg");
                QRCodeUtil.encode(line, "./logo.jpg", out, true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}